<?php
/**
 * @package    gadgets
 * @author     Daniel Botelho <botelho.daniel@gmail.com>
 * @see GadgetsIO::makeRequest()
 */
class GadgetResponse
{
  private $gadget_request;

  function __construct(GadgetRequest $gadget_request)
  {
    $this->gadget_request = $gadget_request;
  }
  
  /**
   * Returns the Javascript function of this response
   *
   * @return JSFunction The Javascript function of this response
   */
  public function getJSFunction()
  {
    return $this->gadget_request->getJSResponseFunction();
  }

  /**
   * Returns the request that has generated this response
   *
   * @return GadgetRequest The request that has generated this response
   */
  public function getGadgetRequest()
  {
    return $this->gadget_request;
  }
  /**
   * text : <raw text of the response>
   * @return string
   */
  public function getText($appendable=false)
  {
  	return StringUtil::appendableString($this->getJSFunction()->getArgs().".text",$appendable);
  }
  /**
   * data : <parsed data, if applicable>
   * @return string
   */
  public function getData($appendable=false)
  {
  	return StringUtil::appendableString($this->getJSFunction()->getArgs().".data",$appendable);
  }
  /**
   * errors : <any errors that occurred>
   * @return string
   */
  public function getErrors($appendable=false)
  {
  	return StringUtil::appendableString($this->getJSFunction()->getArgs().".errors",$appendable);
  }
}